import sys
sys.path.append('..\\..')
from Djoser import *


root = Tk()
f1 = Frame(root)
f1.pack()

lb = DjListbox(f1, scrollbar=True)
lb.pack()
lb.items = map(chr, range(ord('a'),ord('z')))

def test(n):
	#test properties
	if n==0:
		lb.items = ('one','two','three')
		assert tuple(lb.items) == ('one','two','three')
	elif n==1: lb.multiple = not lb.multiple
	elif n==2: lb.enabled = not lb.enabled
	elif n==3:
		lb.bgcolor=(200,255,255)
		lb.color = (255,0,0)
		print lb.bgcolor, lb.color
	elif n==4:
		lb.selectionbgcolor=(0,0,0)
		lb.selectioncolor = (255,0,0)
		print lb.selectionbgcolor, lb.selectioncolor
	elif n==5: 
		lb.borderwidth = 4
		assert str(lb.borderwidth)=='4'
	elif n==6:
		lb.borderstyle = 'raised'
		assert lb.borderstyle == 'raised'
	elif n==7:
		lb.width=4
		lb.height=4
		assert lb.width==4 and lb.height==4
	elif n==8:
		lb.font = ('Times New Roman', 12, 'normal')
		print lb.font
	
	elif n==12:
		lb.style_item(1, foreground='#ff0000')
		assert lb.style_item_get(1, 'foreground')=='#ff0000'
	elif n==13:
		print 'Selection:',lb.get_selection()
		print 'Items:',lb.get_selected_items()
	elif n==14:
		lb.multiple = False
		lb.deselect()
		lb.set_selection(1)
		lb.set_selection(3) #If not multiple, we shouldn't allow multiple selection.
		assert tuple(lb.get_selection())==(3,)
	elif n==15:
		lb.multiple = True
		lb.deselect()
		lb.set_selection(1)
		lb.set_selection(3) #Should allow multiple selection.
		assert tuple(lb.get_selection())==(1,3)
	elif n==16:
		def fn(s): print s
		lb.set_doubleclick_callback(fn)

f = Frame(root)
f.pack()
Button(f,text='resetitems',command=lambda:test(0)).pack(side=LEFT)
Button(f,text='toggle multiselect',command=lambda:test(1)).pack(side=LEFT)
Button(f,text='enable',command=lambda:test(2)).pack(side=LEFT)
Button(f,text='colors',command=lambda:test(3)).pack(side=LEFT)
Button(f,text='selcolors',command=lambda:test(4)).pack(side=LEFT)
Button(f,text='borderwidth',command=lambda:test(5)).pack(side=LEFT)
Button(f,text='borderstyle',command=lambda:test(6)).pack(side=LEFT)
Button(f,text='width/height',command=lambda:test(7)).pack(side=LEFT)
Button(f,text='font',command=lambda:test(8)).pack(side=LEFT)

f2 = Frame(root)
f2.pack()

Button(f2,text='top',command=lambda:lb.scrollto_start()).pack(side=LEFT)
Button(f2,text='end',command=lambda:lb.scrollto_end()).pack(side=LEFT)
Button(f2,text='style_item',command=lambda:test(12)).pack(side=LEFT)
Button(f2,text='add end',command=lambda:lb.add_item('hello',True)).pack(side=LEFT)
Button(f2,text='add here',command=lambda:lb.add_item('hello',False)).pack(side=LEFT)
Button(f2,text='insert',command=lambda:lb.insert_item(1,'inserted')).pack(side=LEFT)
Button(f2,text='delete',command=lambda:lb.delete_item(1)).pack(side=LEFT)
Button(f2,text='get sel',command=lambda:test(13)).pack(side=LEFT)
Button(f2,text='set sel',command=lambda:test(14)).pack(side=LEFT)
Button(f2,text='set sel mult',command=lambda:test(15)).pack(side=LEFT)
Button(f2,text='deselect',command=lambda:lb.deselect()).pack(side=LEFT)
Button(f2,text='clear',command=lambda:lb.clear()).pack(side=LEFT)
Button(f2,text='dblclick',command=lambda:test(16)).pack(side=LEFT)
f.mainloop()
